<?PHP
/****************************************/
/************* IdeaLAN LLC **************/
/* You can view log files whats going   */
/* in your control panel who, what, when*/
/* and where.                           */
/****************************************/
/****************************************/
/* SCRIPT: logs.php          VER: 0.1b  */
/* AUTHOR: Lukasz Piekarski             */
/* E-mail: lukasz@idealan.net           */
/****************************************/
if (empty($_SESSION["sesid"])) { header ("Location: ../in.php?e=0"); }
?>

        <div id="content">
        <div id="left">
            <div class="naglowek"><div class="pkt"></div>Log's</div>
            <ul id="me">
                <li <? if ($view == "") { echo "id=\"press\""; } ?> ><a href="in.php?show=logs">Access Denied Logs</a></li>
                <li <? if ($view == "user") { echo "id=\"press\" "; } ?> ><a href="in.php?show=logs&view=user">User Logs</a></li>
                <li <? if ($view == "system") { echo "id=\"press\" "; } ?> ><a href="in.php?show=logs&view=system">System Logs</a></li>
            </ul>
        </div>					

        <div id="right">

<?

if(isSet($_GET["begin"])) {
    $begin = $_GET["begin"];
} else {
    $begin = 0;
}
if ($view == "user") {   
    
    $rows_on_page = 10;
    $result = LogService::getInstance()->getNumRows($DBprefix,'LOGIN','log_id');
    $linktest ="in.php?show=logs&view=user";
    include ("pages2.php");

    // LETS GET LOGS OF CURRENT USER
    $execute_get_user_logs = LogService::getInstance()->getUserLogLimit($DBprefix,'LOGIN','log_id',$begin,$rows_on_page);
    $user_log_adtries = LogService::getInstance()->getNumRowsLimit($DBprefix,'LOGIN','log_id',$begin,$rows_on_page);


    echo "
            <div class='naglowek'><div class='pkt'></div>User Access</div>
                <div id='rightcont'>
                    <table class='editform1' style='width: 100%'>
                        <tr>
                            <td width='145' class='tableLogsHeader' style='width: 145px'>ID | USER</td>
                            <td width='145' class='tableLogsHeader'>DATE</td>
                            <td width='218' class='tableLogsHeader'>IP ADDRESS</td>
                            <td width='156' class='tableLogsHeader'>STATUS</td>
                        </tr>
    ";

    foreach($execute_get_user_logs as $userLog) {
        $user_log_id = $userLog->getId();
        $user_log_action = $userLog->getAction();
        $user_log_userid = $userLog->getUserId();
        $user_log_pageto = $userLog->getPageTo();
        $user_log_pagefrom = $userLog->getPageFrom();
        $user_log_ip = $userLog->getIp();
        $user_log_date = $userLog->getDate();
        $user_log_indate = $userLog->getInDate();
        $user_log_outdate = $userLog->getOutDate();
        $user_log_status = $userLog->getStatus();
        $user_log_sesexp = $userLog->getSesExp();
        $user_log_sesid = $userLog->getSesId();

        if ($user_log_sesexp <= $timedate) { 
            $user_log_status = "EXPIRED"; 
        }

        $user_log1 = SignupService::getInstance()->getUserInfoById($DBprefix, $user_log_userid);
        $user_log_user_name = $user_log1->getUsername();
        $user_log_username = strtoupper( $user_log1->getUsername() );

        if ($user_log_userid == "1") {
            $show_logout = "";
        } else { 
            $show_logout = "<a href='modify.php?act=change&what=user&set=logout&lid=$user_log_id'><img src='../g/ico/user_go.png'></a>";
        }

        if ($user_log_user_name == "idealan") {
        } else {
            if ($user_log_status == "ACTIVE") {
        ?>

                 <tr onMouseOver="this.className='highlight'" onMouseOut="this.className='normal'">
                    <td width='145' class='tableLogs' style='width: 145px'><?php echo "$user_log_id | $user_log_username" ?></td>
                    <td width='145' class='tableLogs'><?php echo $user_log_date ?></td>
                    <td width='218' class='tableLogs'><?php echo $user_log_ip ?></td>
                    <td width='156' class='tableLogsgreen'><?php echo "$user_log_status $show_logout" ?></td>
                </tr>
        <?php
        } else {
        ?>
                 <tr onMouseOver="this.className='highlight'" onMouseOut="this.className='normal'">
                    <td width='145' class='tableLogs' style='width: 145px'><?php echo "$user_log_id / $user_log_username" ?></td>
                    <td width='145' class='tableLogs'><?php echo $user_log_date ?></td>
                    <td width='218' class='tableLogs'><?php echo $user_log_ip ?></td>
                    <td width='156' class='tableLogs'><?php echo $user_log_status ?></td>
                </tr>
        <?php
        }
        }

    }
    
    echo "</table>";
    echo $pagingStr;
    echo "</div>";


}
